import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'HomePage.dart';
import 'InfoPage.dart';
import 'ProfilePage.dart';
import '../controller/BottomBarController.dart';

class BottomNavPage extends StatelessWidget {
  //全局状态控制器
  final bottomBarController = Get.find<BottomBarController>();

  List bodyPageList = [
    const HomePage(),
    const InfoPage(),
    const ProfilePage(),
  ];

  BottomNavPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //主题
        body: Obx(() => bodyPageList[bottomBarController.index.value]),
        //底部导航条
        bottomNavigationBar: Obx(() => BottomNavigationBar(
              // 当前菜单下标
              currentIndex: bottomBarController.index.value,
              // 点击事件,获取当前点击的标签下标
              onTap: (int index) {
                bottomBarController.setIndex(index);
              },
              iconSize: 30.0,
              fixedColor: Colors.red,
              type: BottomNavigationBarType.fixed,
              items: const [
                BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
                BottomNavigationBarItem(
                    icon: Icon(Icons.category), label: '分类'),
                BottomNavigationBarItem(
                    icon: Icon(Icons.perm_identity), label: "我的")
              ],
            )));
  }
}
